const childProcess = require("child_process");
const express = require("express");
const router = express.Router();
const pwd = "/usr/local/nodejs/shuwan9/codeBase/";
router.get("/pull", (req, res) => {
  const { repo } = req.query;
  if (!repo) {
    res.send(
      JSON.stringify({
        code: -1,
        msg: "请输入repo",
      })
    );
    return;
  }
  childProcess.exec(`cd ${pwd}${repo} && git pull`, (err, stdout) => {
    if (err) {
      res.send(
        JSON.stringify({
          code: 1,
          msg: err.message,
        })
      );
      return;
    }
    res.send(
      JSON.stringify({
        code: 0,
        msg: stdout,
      })
    );
  });
});
module.exports = router;
